home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / gfx / pbm / source / jpegV5.lha / jpegV5 / src / jpeglib.h < prev    next >
C/C++ Source or Header  |  1994-12-23  |  38KB  |  931 lines

  1. /*
  2.  * jpeglib.h
  3.  *
  4.  * Copyright (C) 1991-1994, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file defines the application interface for the JPEG library.
  9.  * Most applications using the library need only include this file,
  10.  * and perhaps jerror.h if they want to know the exact error codes.
  11.  */
  12.  
  13. /*
  14.  * First we include the configuration files that record how this
  15.  * installation of the JPEG library is set up.  jconfig.h can be
  16.  * generated automatically for many systems.  jmorecfg.h contains
  17.  * manual configuration options that most people need not worry about.
  18.  */
  19.  
  20. #ifndef JCONFIG_INCLUDED    /* in case jinclude.h already did */
  21. #include "jconfig.h"        /* widely used configuration options */
  22. #endif
  23. #include "jmorecfg.h"        /* seldom changed options */
  24.  
  25.  
  26. /* Version ID for the JPEG library.
  27.  * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
  28.  */
  29.  
  30. #define JPEG_LIB_VERSION  50    /* Version 5.0 */
  31.  
  32.  
  33. /* Various constants determining the sizes of things.
  34.  * All of these are specified by the JPEG standard, so don't change them
  35.  * if you want to be compatible.
  36.  */
  37.  
  38. #define DCTSIZE            8    /* The basic DCT block is 8x8 samples */
  39. #define DCTSIZE2        64    /* DCTSIZE squared; # of elements in a block */
  40. #define NUM_QUANT_TBLS      4    /* Quantization tables are numbered 0..3 */
  41. #define NUM_HUFF_TBLS       4    /* Huffman tables are numbered 0..3 */
  42. #define NUM_ARITH_TBLS      16    /* Arith-coding tables are numbered 0..15 */
  43. #define MAX_COMPS_IN_SCAN   4    /* JPEG limit on # of components in one scan */
  44. #define MAX_SAMP_FACTOR     4    /* JPEG limit on sampling factors */
  45. #define MAX_BLOCKS_IN_MCU   10    /* JPEG limit on # of blocks in an MCU */
  46.  
  47.  
  48. /* This macro is used to declare a "method", that is, a function pointer.
  49.  * We want to supply prototype parameters if the compiler can cope.
  50.  * Note that the arglist parameter must be parenthesized!
  51.  */
  52.  
  53. #ifdef HAVE_PROTOTYPES
  54. #define JMETHOD(type,methodname,arglist)  type (*methodname) arglist
  55. #else
  56. #define JMETHOD(type,methodname,arglist)  type (*methodname) ()
  57. #endif
  58.  
  59.  
  60. /* Data structures for images (arrays of samples and of DCT coefficients).
  61.  * On 80x86 machines, the image arrays are too big for near pointers,
  62.  * but the pointer arrays can fit in near memory.
  63.  */
  64.  
  65. typedef JSAMPLE FAR *JSAMPROW;    /* ptr to one image row of pixel samples. */
  66. typedef JSAMPROW *JSAMPARRAY;    /* ptr to some rows (a 2-D sample array) */
  67. typedef JSAMPARRAY *JSAMPIMAGE;    /* a 3-D sample array: top index is color */
  68.  
  69. typedef JCOEF JBLOCK[DCTSIZE2];    /* one block of coefficients */
  70. typedef JBLOCK FAR *JBLOCKROW;    /* pointer to one row of coefficient blocks */
  71. typedef JBLOCKROW *JBLOCKARRAY;        /* a 2-D array of coefficient blocks */
  72. typedef JBLOCKARRAY *JBLOCKIMAGE;    /* a 3-D array of coefficient blocks */
  73.  
  74. typedef JCOEF FAR *JCOEFPTR;    /* useful in a couple of places */
  75.  
  76.  
  77. /* Types for JPEG compression parameters and working tables. */
  78.  
  79.  
  80. /* DCT coefficient quantization tables. */
  81.  
  82. typedef struct {
  83.   /* This field directly represents the contents of a JPEG DQT marker.
  84.    * Note: the values are always given in zigzag order.
  85.    */
  86.   UINT16 quantval[DCTSIZE2];    /* quantization step for each coefficient */
  87.   /* This field is used only during compression.  It's initialized FALSE when
  88.    * the table is created, and set TRUE when it's been output to the file.
  89.    * You could suppress output of a table by setting this to TRUE.
  90.    * (See jpeg_suppress_tables for an example.)
  91.    */
  92.   boolean sent_table;        /* TRUE when table has been output */
  93. } JQUANT_TBL;
  94.  
  95.  
  96. /* Huffman coding tables. */
  97.  
  98. typedef struct {
  99.   /* These two fields directly represent the contents of a JPEG DHT marker */
  100.   UINT8 bits[17];        /* bits[k] = # of symbols with codes of */
  101.                 /* length k bits; bits[0] is unused */
  102.   UINT8 huffval[256];        /* The symbols, in order of incr code length */
  103.   /* This field is used only during compression.  It's initialized FALSE when
  104.    * the table is created, and set TRUE when it's been output to the file.
  105.    * You could suppress output of a table by setting this to TRUE.
  106.    * (See jpeg_suppress_tables for an example.)
  107.    */
  108.   boolean sent_table;        /* TRUE when table has been output */
  109. } JHUFF_TBL;
  110.  
  111.  
  112. /* Basic info about one component (color channel). */
  113.  
  114. typedef struct {
  115.   /* These values are fixed over the whole image. */
  116.   /* For compression, they must be supplied by parameter setup; */
  117.   /* for decompression, they are read from the SOF marker. */
  118.   int component_id;        /* identifier for this component (0..255) */
  119.   int component_index;        /* its index in SOF or cinfo->comp_info[] */
  120.   int h_samp_factor;        /* horizontal sampling factor (1..4) */
  121.   int v_samp_factor;        /* vertical sampling factor (1..4) */
  122.   int quant_tbl_no;        /* quantization table selector (0..3) */
  123.   /* These values may vary between scans. */
  124.   /* For compression, they must be supplied by parameter setup; */
  125.   /* for decompression, they are read from the SOS marker. */
  126.   int dc_tbl_no;        /* DC entropy table selector (0..3) */
  127.   int ac_tbl_no;        /* AC entropy table selector (0..3) */
  128.   
  129.   /* Remaining fields should be treated as private by applications. */
  130.   
  131.   /* These values are computed during compression or decompression startup: */
  132.   /* Component's size in DCT blocks.
  133.    * Any dummy blocks added to complete an MCU are not counted; therefore
  134.    * these values do not depend on whether a scan is interleaved or not.
  135.    */
  136.   JDIMENSION width_in_blocks;
  137.   JDIMENSION height_in_blocks;
  138.   /* Size of a DCT block in samples.  Always DCTSIZE for compression.
  139.    * For decompression this is the size of the output from one DCT block,
  140.    * reflecting any scaling we choose to apply during the IDCT step.
  141.    * Values of 1,2,4,8 are likely to be supported.  Note that different
  142.    * components may receive different IDCT scalings.
  143.    */
  144.   int DCT_scaled_size;
  145.   /* The downsampled dimensions are the component's actual, unpadded number
  146.    * of samples at the main buffer (preprocessing/compression interface), thus
  147.    * downsampled_width = ceil(image_width * Hi/Hmax)
  148.    * and similarly for height.  For decompression, IDCT scaling is included, so
  149.    * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
  150.    */
  151.   JDIMENSION downsampled_width;     /* actual width in samples */
  152.   JDIMENSION downsampled_height; /* actual height in samples */
  153.   /* This flag is used only for decompression.  In cases where some of the
  154.    * components will be ignored (eg grayscale output from YCbCr image),
  155.    * we can skip most computations for the unused components.
  156.    */
  157.   boolean component_needed;    /* do we need the value of this component? */
  158.  
  159.   /* These values are computed before starting a scan of the component: */
  160.   int MCU_width;        /* number of blocks per MCU, horizontally */
  161.   int MCU_height;        /* number of blocks per MCU, vertically */
  162.   int MCU_blocks;        /* MCU_width * MCU_height */
  163.   int MCU_sample_width;        /* MCU width in samples, MCU_width*DCT_scaled_size */
  164.   int last_col_width;        /* # of non-dummy blocks across in last MCU */
  165.   int last_row_height;        /* # of non-dummy blocks down in last MCU */
  166.  
  167.   /* Private per-component storage for DCT or IDCT subsystem. */
  168.   void * dct_table;
  169. } jpeg_component_info;
  170.  
  171.  
  172. /* Known color spaces. */
  173.  
  174. typedef enum {
  175.     JCS_UNKNOWN,        /* error/unspecified */
  176.     JCS_GRAYSCALE,        /* monochrome */
  177.     JCS_RGB,        /* red/green/blue */
  178.     JCS_YCbCr,        /* Y/Cb/Cr (also known as YUV) */
  179.     JCS_CMYK,        /* C/M/Y/K */
  180.     JCS_YCCK        /* Y/Cb/Cr/K */
  181. } J_COLOR_SPACE;
  182.  
  183. /* DCT/IDCT algorithm options. */
  184.  
  185. typedef enum {
  186.     JDCT_ISLOW,        /* slow but accurate integer algorithm */
  187.     JDCT_IFAST,        /* faster, less accurate integer method */
  188.     JDCT_FLOAT        /* floating-point: accurate, fast on fast HW */
  189. } J_DCT_METHOD;
  190.  
  191. #ifndef JDCT_DEFAULT        /* may be overridden in jconfig.h */
  192. #define JDCT_DEFAULT  JDCT_ISLOW
  193. #endif
  194. #ifndef JDCT_FASTEST        /* may be overridden in jconfig.h */
  195. #define JDCT_FASTEST  JDCT_IFAST
  196. #endif
  197.  
  198. /* Dithering options for decompression. */
  199.  
  200. typedef enum {
  201.     JDITHER_NONE,        /* no dithering */
  202.     JDITHER_ORDERED,    /* simple ordered dither */
  203.     JDITHER_FS        /* Floyd-Steinberg error diffusion dither */
  204. } J_DITHER_MODE;
  205.  
  206.  
  207. /* Common fields between JPEG compression and decompression master structs. */
  208.  
  209. #define jpeg_common_fields \
  210.   struct jpeg_error_mgr * err;    /* Error handler module */\
  211.   struct jpeg_memory_mgr * mem;    /* Memory manager module */\
  212.   struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  213.   boolean is_decompressor;    /* so common code can tell which is which */\
  214.   int global_state        /* for checking call sequence validity */
  215.  
  216. /* Routines that are to be used by both halves of the library are declared
  217.  * to receive a pointer to this structure.  There are no actual instances of
  218.  * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.
  219.  */
  220. struct jpeg_common_struct {
  221.   jpeg_common_fields;        /* Fields common to both master struct types */
  222.   /* Additional fields follow in an actual jpeg_compress_struct or
  223.    * jpeg_decompress_struct.  All three structs must agree on these
  224.    * initial fields!  (This would be a lot cleaner in C++.)
  225.    */
  226. };
  227.  
  228. typedef struct jpeg_common_struct * j_common_ptr;
  229. typedef struct jpeg_compress_struct * j_compress_ptr;
  230. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  231.  
  232.  
  233. /* Master record for a compression instance */
  234.  
  235. struct jpeg_compress_struct {
  236.   jpeg_common_fields;        /* Fields shared with jpeg_decompress_struct */
  237.  
  238.   /* Destination for compressed data */
  239.   struct jpeg_destination_mgr * dest;
  240.  
  241.   /* Description of source image --- these fields must be filled in by
  242.    * outer application before starting compression.  in_color_space must
  243.    * be correct before you can even call jpeg_set_defaults().
  244.    */
  245.  
  246.   JDIMENSION image_width;    /* input image width */
  247.   JDIMENSION image_height;    /* input image height */
  248.   int input_components;        /* # of color components in input image */
  249.   J_COLOR_SPACE in_color_space;    /* colorspace of input image */
  250.  
  251.   double input_gamma;        /* image gamma of input image */
  252.  
  253.   /* Compression parameters --- these fields must be set before calling
  254.    * jpeg_start_compress().  We recommend calling jpeg_set_defaults() to
  255.    * initialize everything to reasonable defaults, then changing anything
  256.    * the application specifically wants to change.  That way you won't get
  257.    * burnt when new parameters are added.  Also note that there are several
  258.    * helper routines to simplify changing parameters.
  259.    */
  260.  
  261.   int data_precision;        /* bits of precision in image data */
  262.  
  263.   int num_components;        /* # of color components in JPEG image */
  264.   J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  265.  
  266.   jpeg_component_info * comp_info;
  267.   /* comp_info[i] describes component that appears i'th in SOF */
  268.   
  269.   JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  270.   /* ptrs to coefficient quantization tables, or NULL if not defined */
  271.   
  272.   JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  273.   JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  274.   /* ptrs to Huffman coding tables, or NULL if not defined */
  275.   
  276.   UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  277.   UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  278.   UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  279.  
  280.   boolean raw_data_in;        /* TRUE=caller supplies downsampled data */
  281.   boolean arith_code;        /* TRUE=arithmetic coding, FALSE=Huffman */
  282.   boolean interleave;        /* TRUE=interleaved output, FALSE=not */
  283.   boolean optimize_coding;    /* TRUE=optimize entropy encoding parms */
  284.   boolean CCIR601_sampling;    /* TRUE=first samples are cosited */
  285.   int smoothing_factor;        /* 1..100, or 0 for no input smoothing */
  286.   J_DCT_METHOD dct_method;    /* DCT algorithm selector */
  287.  
  288.   /* The restart interval can be specified in absolute MCUs by setting
  289.    * restart_interval, or in MCU rows by setting restart_in_rows
  290.    * (in which case the correct restart_interval will be figured
  291.    * for each scan).
  292.    */
  293.   unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  294.   int restart_in_rows;        /* if > 0, MCU rows per restart interval */
  295.  
  296.   /* Parameters controlling emission of special markers. */
  297.  
  298.   boolean write_JFIF_header;    /* should a JFIF marker be written? */
  299.   /* These three values are not used by the JPEG code, merely copied */
  300.   /* into the JFIF APP0 marker.  density_unit can be 0 for unknown, */
  301.   /* 1 for dots/inch, or 2 for dots/cm.  Note that the pixel aspect */
  302.   /* ratio is defined by X_density/Y_density even when density_unit=0. */
  303.   UINT8 density_unit;        /* JFIF code for pixel size units */
  304.   UINT16 X_density;        /* Horizontal pixel density */
  305.   UINT16 Y_density;        /* Vertical pixel density */
  306.   boolean write_Adobe_marker;    /* should an Adobe marker be written? */
  307.   
  308.   /* State variable: index of next scanline to be written to
  309.    * jpeg_write_scanlines().  Application may use this to control its
  310.    * processing loop, e.g., "while (next_scanline < image_height)".
  311.    */
  312.  
  313.   JDIMENSION next_scanline;    /* 0 .. image_height-1  */
  314.  
  315.   /* Remaining fields are known throughout compressor, but generally
  316.    * should not be touched by a surrounding application.
  317.    */
  318.  
  319.   /*
  320.    * These fields are computed during compression startup
  321.    */
  322.   int max_h_samp_factor;    /* largest h_samp_factor */
  323.   int max_v_samp_factor;    /* largest v_samp_factor */
  324.  
  325.   JDIMENSION total_iMCU_rows;    /* # of iMCU rows to be input to coef ctlr */
  326.   /* The coefficient controller receives data in units of MCU rows as defined
  327.    * for fully interleaved scans (whether the JPEG file is interleaved or not).
  328.    * There are v_samp_factor * DCTSIZE sample rows of each component in an
  329.    * "iMCU" (interleaved MCU) row.
  330.    */
  331.   
  332.   /*
  333.    * These fields are valid during any one scan.
  334.    * They describe the components and MCUs actually appearing in the scan.
  335.    */
  336.   int comps_in_scan;        /* # of JPEG components in this scan */
  337.   jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  338.   /* *cur_comp_info[i] describes component that appears i'th in SOS */
  339.   
  340.   JDIMENSION MCUs_per_row;    /* # of MCUs across the image */
  341.   JDIMENSION MCU_rows_in_scan;    /* # of MCU rows in the image */
  342.   
  343.   int blocks_in_MCU;        /* # of DCT blocks per MCU */
  344.   int MCU_membership[MAX_BLOCKS_IN_MCU];
  345.   /* MCU_membership[i] is index in cur_comp_info of component owning */
  346.   /* i'th block in an MCU */
  347.  
  348.   /*
  349.    * Links to compression subobjects (methods and private variables of modules)
  350.    */
  351.   struct jpeg_comp_master * master;
  352.   struct jpeg_c_main_controller * main;
  353.   struct jpeg_c_prep_controller * prep;
  354.   struct jpeg_c_coef_controller * coef;
  355.   struct jpeg_marker_writer * marker;
  356.   struct jpeg_color_converter * cconvert;
  357.   struct jpeg_downsampler * downsample;
  358.   struct jpeg_forward_dct * fdct;
  359.   struct jpeg_entropy_encoder * entropy;
  360. };
  361.  
  362.  
  363. /* Master record for a decompression instance */
  364.  
  365. struct jpeg_decompress_struct {
  366.   jpeg_common_fields;        /* Fields shared with jpeg_compress_struct */
  367.  
  368.   /* Source of compressed data */
  369.   struct jpeg_source_mgr * src;
  370.  
  371.   /* Basic description of image --- filled in by jpeg_read_header(). */
  372.   /* Application may inspect these values to decide how to process image. */
  373.  
  374.   JDIMENSION image_width;    /* nominal image width (from SOF marker) */
  375.   JDIMENSION image_height;    /* nominal image height */
  376.   int num_components;        /* # of color components in JPEG image */
  377.   J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  378.  
  379.   /* Decompression processing parameters --- these fields must be set before
  380.    * calling jpeg_start_decompress().  Note that jpeg_read_header() initializes
  381.    * them to default values.
  382.    */
  383.  
  384.   J_COLOR_SPACE out_color_space; /* colorspace for output */
  385.  
  386.   unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  387.  
  388.   double output_gamma;        /* image gamma wanted in output */
  389.  
  390.   boolean raw_data_out;        /* TRUE=downsampled data wanted */
  391.  
  392.   boolean quantize_colors;    /* TRUE=colormapped output wanted */
  393.   /* the following are ignored if not quantize_colors: */
  394.   boolean two_pass_quantize;    /* TRUE=use two-pass color quantization */
  395.   J_DITHER_MODE dither_mode;    /* type of color dithering to use */
  396.   int desired_number_of_colors;    /* max number of colors to use */
  397.  
  398.   J_DCT_METHOD dct_method;    /* DCT algorithm selector */
  399.   boolean do_fancy_upsampling;    /* TRUE=apply fancy upsampling */
  400.  
  401.   /* Description of actual output image that will be returned to application.
  402.    * These fields are computed by jpeg_start_decompress().
  403.    * You can also use jpeg_calc_output_dimensions() to determine these values
  404.    * in advance of calling jpeg_start_decompress().
  405.    */
  406.  
  407.   JDIMENSION output_width;    /* scaled image width */
  408.   JDIMENSION output_height;    /* scaled image height */
  409.   int out_color_components;    /* # of color components in out_color_space */
  410.   int output_components;    /* # of color components returned */
  411.   /* output_components is 1 (a colormap index) when quantizing colors;
  412.    * otherwise it equals out_color_components.
  413.    */
  414.   int rec_outbuf_height;    /* min recommended height of scanline buffer */
  415.   /* If the buffer passed to jpeg_read_scanlines() is less than this many rows
  416.    * high, space and time will be wasted due to unnecessary data copying.
  417.    * Usually rec_outbuf_height will be 1 or 2, at most 4.
  418.    */
  419.  
  420.   /* When quantizing colors, the output colormap is described by these fields.
  421.    * The application can supply a colormap by setting colormap non-NULL before
  422.    * calling jpeg_start_decompress; otherwise a colormap is created during
  423.    * jpeg_start_decompress.
  424.    * The map has out_color_components rows and actual_number_of_colors columns.
  425.    */
  426.   int actual_number_of_colors;    /* number of entries in use */
  427.   JSAMPARRAY colormap;        /* The color map as a 2-D pixel array */
  428.  
  429.   /* State variable: index of next scaled scanline to be read from
  430.    * jpeg_read_scanlines().  Application may use this to control its
  431.    * processing loop, e.g., "while (output_scanline < output_height)".
  432.    */
  433.  
  434.   JDIMENSION output_scanline;    /* 0 .. output_height-1  */
  435.  
  436.   /* Internal JPEG parameters --- the application usually need not look at
  437.    * these fields.
  438.    */
  439.  
  440.   /* Quantization and Huffman tables are carried forward across input
  441.    * datastreams when processing abbreviated JPEG datastreams.
  442.    */
  443.  
  444.   JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  445.   /* ptrs to coefficient quantization tables, or NULL if not defined */
  446.  
  447.   JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  448.   JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  449.   /* ptrs to Huffman coding tables, or NULL if not defined */
  450.  
  451.   /* These parameters are never carried across datastreams, since they
  452.    * are given in SOF/SOS markers or defined to be reset by SOI.
  453.    */
  454.  
  455.   int data_precision;        /* bits of precision in image data */
  456.  
  457.   jpeg_component_info * comp_info;
  458.   /* comp_info[i] describes component that appears i'th in SOF */
  459.  
  460.   UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  461.   UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  462.   UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  463.  
  464.   boolean arith_code;        /* TRUE=arithmetic coding, FALSE=Huffman */
  465.  
  466.   unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  467.  
  468.   /* These fields record data obtained from optional markers recognized by
  469.    * the JPEG library.
  470.    */
  471.   boolean saw_JFIF_marker;    /* TRUE iff a JFIF APP0 marker was found */
  472.   /* Data copied from JFIF marker: */
  473.   UINT8 density_unit;        /* JFIF code for pixel size units */
  474.   UINT16 X_density;        /* Horizontal pixel density */
  475.   UINT16 Y_density;        /* Vertical pixel density */
  476.   boolean saw_Adobe_marker;    /* TRUE iff an Adobe APP14 marker was found */
  477.   UINT8 Adobe_transform;    /* Color transform code from Adobe marker */
  478.  
  479.   boolean CCIR601_sampling;    /* TRUE=first samples are cosited */
  480.  
  481.   /* Remaining fields are known throughout decompressor, but generally
  482.    * should not be touched by a surrounding application.
  483.    */
  484.  
  485.   /*
  486.    * These fields are computed during decompression startup
  487.    */
  488.   int max_h_samp_factor;    /* largest h_samp_factor */
  489.   int max_v_samp_factor;    /* largest v_samp_factor */
  490.  
  491.   int min_DCT_scaled_size;    /* smallest DCT_scaled_size of any component */
  492.  
  493.   JDIMENSION total_iMCU_rows;    /* # of iMCU rows to be output by coef ctlr */
  494.   /* The coefficient controller outputs data in units of MCU rows as defined
  495.    * for fully interleaved scans (whether the JPEG file is interleaved or not).
  496.    * There are v_samp_factor * DCT_scaled_size sample rows of each component
  497.    * in an "iMCU" (interleaved MCU) row.
  498.    */
  499.  
  500.   JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  501.  
  502.   /*
  503.    * These fields are valid during any one scan.
  504.    * They describe the components and MCUs actually appearing in the scan.
  505.    */
  506.   int comps_in_scan;        /* # of JPEG components in this scan */
  507.   jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  508.   /* *cur_comp_info[i] describes component that appears i'th in SOS */
  509.  
  510.   JDIMENSION MCUs_per_row;    /* # of MCUs across the image */
  511.   JDIMENSION MCU_rows_in_scan;    /* # of MCU rows in the image */
  512.  
  513.   int blocks_in_MCU;        /* # of DCT blocks per MCU */
  514.   int MCU_membership[MAX_BLOCKS_IN_MCU];
  515.   /* MCU_membership[i] is index in cur_comp_info of component owning */
  516.   /* i'th block in an MCU */
  517.  
  518.   /* This field is shared between entropy decoder and marker parser.
  519.    * It is either zero or the code of a JPEG marker that has been
  520.    * read from the data source, but has not yet been processed.
  521.    */
  522.   int unread_marker;
  523.  
  524.   /*
  525.    * Links to decompression subobjects (methods, private variables of modules)
  526.    */
  527.   struct jpeg_decomp_master * master;
  528.   struct jpeg_d_main_controller * main;
  529.   struct jpeg_d_coef_controller * coef;
  530.   struct jpeg_d_post_controller * post;
  531.   struct jpeg_marker_reader * marker;
  532.   struct jpeg_entropy_decoder * entropy;
  533.   struct jpeg_inverse_dct * idct;
  534.   struct jpeg_upsampler * upsample;
  535.   struct jpeg_color_deconverter * cconvert;
  536.   struct jpeg_color_quantizer * cquantize;
  537. };
  538.  
  539.  
  540. /* "Object" declarations for JPEG modules that may be supplied or called
  541.  * directly by the surrounding application.
  542.  * As with all objects in the JPEG library, these structs only define the
  543.  * publicly visible methods and state variables of a module.  Additional
  544.  * private fields may exist after the public ones.
  545.  */
  546.  
  547.  
  548. /* Error handler object */
  549.  
  550. struct jpeg_error_mgr {
  551.   /* Error exit handler: does not return to caller */
  552.   JMETHOD(void, error_exit, (j_common_ptr cinfo));
  553.   /* Conditionally emit a trace or warning message */
  554.   JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  555.   /* Routine that actually outputs a trace or error message */
  556.   JMETHOD(void, output_message, (j_common_ptr cinfo));
  557.   /* Format a message string for the most recent JPEG error or message */
  558.   JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  559. #define JMSG_LENGTH_MAX  200    /* recommended size of format_message buffer */
  560.   /* Reset error state variables at start of a new image */
  561.   JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  562.   
  563.   /* The message ID code and any parameters are saved here.
  564.    * A message can have one string parameter or up to 8 int parameters.
  565.    */
  566.   int msg_code;
  567. #define JMSG_STR_PARM_MAX  80
  568.   union {
  569.     int i[8];
  570.     char s[JMSG_STR_PARM_MAX];
  571.   } msg_parm;
  572.   
  573.   /* Standard state variables for error facility */
  574.   
  575.   int trace_level;        /* max msg_level that will be displayed */
  576.   
  577.   /* For recoverable corrupt-data errors, we emit a warning message,
  578.    * but keep going unless emit_message chooses to abort.  emit_message
  579.    * should count warnings in num_warnings.  The surrounding application
  580.    * can check for bad data by seeing if num_warnings is nonzero at the
  581.    * end of processing.
  582.    */
  583.   long num_warnings;        /* number of corrupt-data warnings */
  584.  
  585.   /* These fields point to the table(s) of error message strings.
  586.    * An application can change the table pointer to switch to a different
  587.    * message list (typically, to change the language in which errors are
  588.    * reported).  Some applications may wish to add additional error codes
  589.    * that will be handled by the JPEG library error mechanism; the second
  590.    * table pointer is used for this purpose.
  591.    *
  592.    * First table includes all errors generated by JPEG library itself.
  593.    * Error code 0 is reserved for a "no such error string" message.
  594.    */
  595.   const char * const * jpeg_message_table; /* Library errors */
  596.   int last_jpeg_message;    /* Table contains strings 0..last_jpeg_message */
  597.   /* Second table can be added by application (see cjpeg/djpeg for example).
  598.    * It contains strings numbered first_addon_message..last_addon_message.
  599.    */
  600.   const char * const * addon_message_table; /* Non-library errors */
  601.   int first_addon_message;    /* code for first string in addon table */
  602.   int last_addon_message;    /* code for last string in addon table */
  603. };
  604.  
  605.  
  606. /* Progress monitor object */
  607.  
  608. struct jpeg_progress_mgr {
  609.   JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  610.  
  611.   long pass_counter;        /* work units completed in this pass */
  612.   long pass_limit;        /* total number of work units in this pass */
  613.   int completed_passes;        /* passes completed so far */
  614.   int total_passes;        /* total number of passes expected */
  615. };
  616.  
  617.  
  618. /* Data destination object for compression */
  619.  
  620. struct jpeg_destination_mgr {
  621.   JOCTET * next_output_byte;    /* => next byte to write in buffer */
  622.   size_t free_in_buffer;    /* # of byte spaces remaining in buffer */
  623.  
  624.   JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  625.   JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  626.   JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  627. };
  628.  
  629.  
  630. /* Data source object for decompression */
  631.  
  632. struct jpeg_source_mgr {
  633.   const JOCTET * next_input_byte; /* => next byte to read from buffer */
  634.   size_t bytes_in_buffer;    /* # of bytes remaining in buffer */
  635.  
  636.   JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  637.   JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  638.   JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  639.   JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo));
  640.   JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  641. };
  642.  
  643.  
  644. /* Memory manager object.
  645.  * Allocates "small" objects (a few K total), "large" objects (tens of K),
  646.  * and "really big" objects (virtual arrays with backing store if needed).
  647.  * The memory manager does not allow individual objects to be freed; rather,
  648.  * each created object is assigned to a pool, and whole pools can be freed
  649.  * at once.  This is faster and more convenient than remembering exactly what
  650.  * to free, especially where malloc()/free() are not too speedy.
  651.  * NB: alloc routines never return NULL.  They exit to error_exit if not
  652.  * successful.
  653.  */
  654.  
  655. #define JPOOL_PERMANENT    0    /* lasts until master record is destroyed */
  656. #define JPOOL_IMAGE    1    /* lasts until done with image/datastream */
  657. #define JPOOL_NUMPOOLS    2
  658.  
  659. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  660. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  661.  
  662.  
  663. struct jpeg_memory_mgr {
  664.   /* Method pointers */
  665.   JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  666.                 size_t sizeofobject));
  667.   JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  668.                      size_t sizeofobject));
  669.   JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  670.                      JDIMENSION samplesperrow,
  671.                      JDIMENSION numrows));
  672.   JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  673.                       JDIMENSION blocksperrow,
  674.                       JDIMENSION numrows));
  675.   JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  676.                           int pool_id,
  677.                           JDIMENSION samplesperrow,
  678.                           JDIMENSION numrows,
  679.                           JDIMENSION unitheight));
  680.   JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  681.                           int pool_id,
  682.                           JDIMENSION blocksperrow,
  683.                           JDIMENSION numrows,
  684.                           JDIMENSION unitheight));
  685.   JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  686.   JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  687.                        jvirt_sarray_ptr ptr,
  688.                        JDIMENSION start_row,
  689.                        boolean writable));
  690.   JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  691.                         jvirt_barray_ptr ptr,
  692.                         JDIMENSION start_row,
  693.                         boolean writable));
  694.   JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  695.   JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  696.  
  697.   /* Limit on memory allocation for this JPEG object.  (Note that this is
  698.    * merely advisory, not a guaranteed maximum; it only affects the space
  699.    * used for virtual-array buffers.)  May be changed by outer application
  700.    * after creating the JPEG object.
  701.    */
  702.   long max_memory_to_use;
  703. };
  704.  
  705.  
  706. /* Routine signature for application-supplied marker processing methods.
  707.  * Need not pass marker code since it is stored in cinfo->unread_marker.
  708.  */
  709. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  710.  
  711.  
  712. /* Declarations for routines called by application.
  713.  * The JPP macro hides prototype parameters from compilers that can't cope.
  714.  * Note JPP requires double parentheses.
  715.  */
  716.  
  717. #ifdef HAVE_PROTOTYPES
  718. #define JPP(arglist)    arglist
  719. #else
  720. #define JPP(arglist)    ()
  721. #endif
  722.  
  723.  
  724. /* Short forms of external names for systems with brain-damaged linkers.
  725.  * We shorten external names to be unique in the first six letters, which
  726.  * is good enough for all known systems.
  727.  * (If your compiler itself needs names to be unique in less than 15 
  728.  * characters, you are out of luck.  Get a better compiler.)
  729.  */
  730.  
  731. #ifdef NEED_SHORT_EXTERNAL_NAMES
  732. #define jpeg_std_error        jStdError
  733. #define jpeg_create_compress    jCreaCompress
  734. #define jpeg_create_decompress    jCreaDecompress
  735. #define jpeg_destroy_compress    jDestCompress
  736. #define jpeg_destroy_decompress    jDestDecompress
  737. #define jpeg_stdio_dest        jStdDest
  738. #define jpeg_stdio_src        jStdSrc
  739. #define jpeg_set_defaults    jSetDefaults
  740. #define jpeg_set_colorspace    jSetColorspace
  741. #define jpeg_default_colorspace    jDefColorspace
  742. #define jpeg_set_quality    jSetQuality
  743. #define jpeg_set_linear_quality    jSetLQuality
  744. #define jpeg_add_quant_table    jAddQuantTable
  745. #define jpeg_quality_scaling    jQualityScaling
  746. #define jpeg_suppress_tables    jSuppressTables
  747. #define jpeg_alloc_quant_table    jAlcQTable
  748. #define jpeg_alloc_huff_table    jAlcHTable
  749. #define jpeg_start_compress    jStrtCompress
  750. #define jpeg_write_scanlines    jWrtScanlines
  751. #define jpeg_finish_compress    jFinCompress
  752. #define jpeg_write_raw_data    jWrtRawData
  753. #define jpeg_write_marker    jWrtMarker
  754. #define jpeg_write_tables    jWrtTables
  755. #define jpeg_read_header    jReadHeader
  756. #define jpeg_start_decompress    jStrtDecompress
  757. #define jpeg_read_scanlines    jReadScanlines
  758. #define jpeg_finish_decompress    jFinDecompress
  759. #define jpeg_read_raw_data    jReadRawData
  760. #define jpeg_calc_output_dimensions    jCalcDimensions
  761. #define jpeg_set_marker_processor    jSetMarker
  762. #define jpeg_abort_compress    jAbrtCompress
  763. #define jpeg_abort_decompress    jAbrtDecompress
  764. #define jpeg_abort        jAbort
  765. #define jpeg_destroy        jDestroy
  766. #define jpeg_resync_to_restart    jResyncRestart
  767. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  768.  
  769.  
  770. /* Default error-management setup */
  771. EXTERN struct jpeg_error_mgr *jpeg_std_error JPP((struct jpeg_error_mgr *err));
  772.  
  773. /* Initialization and destruction of JPEG compression objects */
  774. /* NB: you must set up the error-manager BEFORE calling jpeg_create_xxx */
  775. EXTERN void jpeg_create_compress JPP((j_compress_ptr cinfo));
  776. EXTERN void jpeg_create_decompress JPP((j_decompress_ptr cinfo));
  777. EXTERN void jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  778. EXTERN void jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  779.  
  780. /* Standard data source and destination managers: stdio streams. */
  781. /* Caller is responsible for opening the file before and closing after. */
  782. EXTERN void jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  783. EXTERN void jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  784.  
  785. /* Default parameter setup for compression */
  786. EXTERN void jpeg_set_defaults JPP((j_compress_ptr cinfo));
  787. /* Compression parameter setup aids */
  788. EXTERN void jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  789.                      J_COLOR_SPACE colorspace));
  790. EXTERN void jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  791. EXTERN void jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  792.                   boolean force_baseline));
  793. EXTERN void jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  794.                      int scale_factor,
  795.                      boolean force_baseline));
  796. EXTERN void jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  797.                       const unsigned int *basic_table,
  798.                       int scale_factor,
  799.                       boolean force_baseline));
  800. EXTERN int jpeg_quality_scaling JPP((int quality));
  801. EXTERN void jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  802.                       boolean suppress));
  803. EXTERN JQUANT_TBL * jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  804. EXTERN JHUFF_TBL * jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  805.  
  806. /* Main entry points for compression */
  807. EXTERN void jpeg_start_compress JPP((j_compress_ptr cinfo,
  808.                      boolean write_all_tables));
  809. EXTERN JDIMENSION jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  810.                         JSAMPARRAY scanlines,
  811.                         JDIMENSION num_lines));
  812. EXTERN void jpeg_finish_compress JPP((j_compress_ptr cinfo));
  813.  
  814. /* Replaces jpeg_write_scanlines when writing raw downsampled data. */
  815. EXTERN JDIMENSION jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  816.                        JSAMPIMAGE data,
  817.                        JDIMENSION num_lines));
  818.  
  819. /* Write a special marker.  See libjpeg.doc concerning safe usage. */
  820. EXTERN void jpeg_write_marker JPP((j_compress_ptr cinfo, int marker,
  821.                    const JOCTET *dataptr, unsigned int datalen));
  822.  
  823. /* Alternate compression function: just write an abbreviated table file */
  824. EXTERN void jpeg_write_tables JPP((j_compress_ptr cinfo));
  825.  
  826. /* Decompression startup: read start of JPEG datastream to see what's there */
  827. EXTERN int jpeg_read_header JPP((j_decompress_ptr cinfo,
  828.                  boolean require_image));
  829. /* Return value is one of: */
  830. #define JPEG_HEADER_OK        0 /* Found valid image datastream */
  831. #define JPEG_HEADER_TABLES_ONLY    1 /* Found valid table-specs-only datastream */
  832. #define JPEG_SUSPENDED        2 /* Had to suspend before end of headers */
  833. /* If you pass require_image = TRUE (normal case), you need not check for
  834.  * a TABLES_ONLY return code; an abbreviated file will cause an error exit.
  835.  * JPEG_SUSPENDED is only possible if you use a data source module that can
  836.  * give a suspension return (the stdio source module doesn't).
  837.  */
  838.  
  839. /* Main entry points for decompression */
  840. EXTERN void jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  841. EXTERN JDIMENSION jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  842.                        JSAMPARRAY scanlines,
  843.                        JDIMENSION max_lines));
  844. EXTERN boolean jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  845.  
  846. /* Replaces jpeg_read_scanlines when reading raw downsampled data. */
  847. EXTERN JDIMENSION jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  848.                       JSAMPIMAGE data,
  849.                       JDIMENSION max_lines));
  850.  
  851. /* Precalculate output dimensions for current decompression parameters. */
  852. EXTERN void jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  853.  
  854. /* Install a special processing method for COM or APPn markers. */
  855. EXTERN void jpeg_set_marker_processor JPP((j_decompress_ptr cinfo,
  856.                        int marker_code,
  857.                        jpeg_marker_parser_method routine));
  858.  
  859. /* If you choose to abort compression or decompression before completing
  860.  * jpeg_finish_(de)compress, then you need to clean up to release memory,
  861.  * temporary files, etc.  You can just call jpeg_destroy_(de)compress
  862.  * if you're done with the JPEG object, but if you want to clean it up and
  863.  * reuse it, call this:
  864.  */
  865. EXTERN void jpeg_abort_compress JPP((j_compress_ptr cinfo));
  866. EXTERN void jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  867.  
  868. /* Generic versions of jpeg_abort and jpeg_destroy that work on either
  869.  * flavor of JPEG object.  These may be more convenient in some places.
  870.  */
  871. EXTERN void jpeg_abort JPP((j_common_ptr cinfo));
  872. EXTERN void jpeg_destroy JPP((j_common_ptr cinfo));
  873.  
  874. /* Default restart-marker-resync procedure for use by data source modules */
  875. EXTERN boolean jpeg_resync_to_restart JPP((j_decompress_ptr cinfo));
  876.  
  877.  
  878. /* These marker codes are exported since applications and data source modules
  879.  * are likely to want to use them.
  880.  */
  881.  
  882. #define JPEG_RST0    0xD0    /* RST0 marker code */
  883. #define JPEG_EOI    0xD9    /* EOI marker code */
  884. #define JPEG_APP0    0xE0    /* APP0 marker code */
  885. #define JPEG_COM    0xFE    /* COM marker code */
  886.  
  887.  
  888. /* If we have a brain-damaged compiler that emits warnings (or worse, errors)
  889.  * for structure definitions that are never filled in, keep it quiet by
  890.  * supplying dummy definitions for the various substructures.
  891.  */
  892.  
  893. #ifdef INCOMPLETE_TYPES_BROKEN
  894. #ifndef JPEG_INTERNALS        /* will be defined in jpegint.h */
  895. struct jvirt_sarray_control { long dummy; };
  896. struct jvirt_barray_control { long dummy; };
  897. struct jpeg_comp_master { long dummy; };
  898. struct jpeg_c_main_controller { long dummy; };
  899. struct jpeg_c_prep_controller { long dummy; };
  900. struct jpeg_c_coef_controller { long dummy; };
  901. struct jpeg_marker_writer { long dummy; };
  902. struct jpeg_color_converter { long dummy; };
  903. struct jpeg_downsampler { long dummy; };
  904. struct jpeg_forward_dct { long dummy; };
  905. struct jpeg_entropy_encoder { long dummy; };
  906. struct jpeg_decomp_master { long dummy; };
  907. struct jpeg_d_main_controller { long dummy; };
  908. struct jpeg_d_coef_controller { long dummy; };
  909. struct jpeg_d_post_controller { long dummy; };
  910. struct jpeg_marker_reader { long dummy; };
  911. struct jpeg_entropy_decoder { long dummy; };
  912. struct jpeg_inverse_dct { long dummy; };
  913. struct jpeg_upsampler { long dummy; };
  914. struct jpeg_color_deconverter { long dummy; };
  915. struct jpeg_color_quantizer { long dummy; };
  916. #endif /* JPEG_INTERNALS */
  917. #endif /* INCOMPLETE_TYPES_BROKEN */
  918.  
  919.  
  920. /*
  921.  * The JPEG library modules define JPEG_INTERNALS before including this file.
  922.  * The internal structure declarations are read only when that is true.
  923.  * Applications using the library should not include jpegint.h, but may wish
  924.  * to include jerror.h.
  925.  */
  926.  
  927. #ifdef JPEG_INTERNALS
  928. #include "jpegint.h"        /* fetch private declarations */
  929. #include "jerror.h"        /* fetch error codes too */
  930. #endif
  931.